export function formatDateTime(dateTimeString, format = 'YYYY-MM-DD HH:mm:ss') {
	// 处理可能的时区问题
	const date = new Date(dateTimeString);

	// 获取各个时间部件
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	const hours = String(date.getHours()).padStart(2, '0');
	const minutes = String(date.getMinutes()).padStart(2, '0');
	const seconds = String(date.getSeconds()).padStart(2, '0');

	// 12小时制的小时
	const hours12 = String(date.getHours() % 12 || 12).padStart(2, '0');
	// AM/PM
	const ampm = date.getHours() >= 12 ? 'PM' : 'AM';

	// 星期几（0-6，0表示星期日）
	const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
	const weekday = weekdays[date.getDay()];

	// 根据格式模板替换
	let result = format;

	// 年份
	result = result.replace(/YYYY/g, year);
	result = result.replace(/YY/g, String(year).slice(-2));

	// 月份
	result = result.replace(/MM/g, month);
	result = result.replace(/M/g, String(date.getMonth() + 1));

	// 日期
	result = result.replace(/DD/g, day);
	result = result.replace(/D/g, String(date.getDate()));

	// 小时
	result = result.replace(/HH/g, hours); // 24小时制
	result = result.replace(/hh/g, hours12); // 12小时制
	result = result.replace(/H/g, String(date.getHours()));
	result = result.replace(/h/g, hours12);

	// 分钟
	result = result.replace(/mm/g, minutes);
	result = result.replace(/m/g, String(date.getMinutes()));

	// 秒钟
	result = result.replace(/ss/g, seconds);
	result = result.replace(/s/g, String(date.getSeconds()));

	// AM/PM
	result = result.replace(/A/g, ampm);
	result = result.replace(/a/g, ampm.toLowerCase());

	// 星期
	result = result.replace(/WW/g, '周' + weekday);
	result = result.replace(/W/g, weekday);

	return result;
}